package Try;

import java.io.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class Main17 {
    public static void main(String[] args) throws IOException {
        File f = new File("C:\\Users\\ruanjie\\Desktop\\train.txt");
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
        String line;
        Set<String> set = new HashSet<>();
        while ((line=reader.readLine())!=null){
            String[] strs = line.split(" ");
            set.add(strs[0]);
            set.add(strs[1]);
        }
        System.out.println(set.size());

        reader.close();
        int count = 0;
        File f2 = new File("C:\\Users\\ruanjie\\Desktop\\crosstest.txt");
        BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(f2)));
        String line2;
        while ((line2=reader2.readLine())!=null){
            String[] strs = line2.split(" ");
//            System.out.println(strs[0]);
//            System.out.println(strs[1]);
            if (set.contains(strs[0])||set.contains(strs[1])){
                count++;
            }
        }

        System.out.println(count);
    }
}
